<template>
  <div>
    <FormPanel :list="topFilterList" :cols="3" :labelWidth="100" :collapse="false" :isSubmitBtn="false" />
    <FilterTable
      ref="mainTable"
      :columns="tableColumns"
      columnsRef="aduitOrder"
      :datakey="'records'"
      selectionType="single"
      :dataSource="dataSource"
      :isSelectColumn= false
      :onColumnsChange="columns => (this.tableColumns = columns)"
    >
    </FilterTable>
   
        <div class="dialogBottmView">

      <el-button size="small" type="primary" icon="el-icon-tickets" :loading="loading"
                   @click="aduit(10041001)" vertical-align = "middle">审核通过
                   </el-button>

        <el-button size="small" type="primary" icon="el-icon-tickets" :loading="loading"
                   @click="refuByPurchase" vertical-align = "middle">审核驳回
                   </el-button>
      <el-button @click="closeDialogTop">返 回</el-button>
      
    </div>

  
  
    <BaseDialog v-if="visible" :visible.sync="visible" title="审核" width="40%" show-close="false">
      
                  <span>
                    驳回原因
                    <el-input
                      width="25%"
                      v-model="aduitRem"
                      
                      placeholder="请输入"
                    ></el-input>
                  </span>
                   
                  <br />
                  <br />
                  <span class="dialog-footer">
                    <el-button type="primary" @click="visible=false">取 消</el-button>
                    <el-button type="primary" @click="aduit(10041002)">确 定</el-button>
                  </span>
      
        </BaseDialog>
  
      
    

  </div>
</template>
<script>
import { partbuyStockInItemOEM,auditOrder } from '@/api/partsmanage/aduitOrder/aduitFinancial';
import { dictionary } from '@/utils/dictMixin';
import { byAllInfo } from '@/api/part/allocation';
import { getStorageList, querySysParam } from '@/api/part/common';
import {ddlxArr, ddztArr, ddtblxArr} from './constant';

export default {
  name: 'partBuyItems',
  props: {
    top: {}
  },
  mixins: [dictionary],
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      tableColumns: this.createTableColumns(),
      fetchParams: {},
      dataSource: [],
      storageDic: [
        { text: 'OEM电', value: 'OEM-ELECTIC' },
        { text: 'OEM油', value: 'OEM-OIL' }
      ], // 仓库字典
      visible: false,
      loading: false,
      aduitRem:'',
      
    };
  },
  mounted() {
    // this.translate(this.top.CUSTOMER_CODE);
    // this.getStorage();
    this.findBuyItems();
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'DEALER_CODE',
          initialValue: '',
         
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'DEALER_NAME',
          initialValue: '',
          
          disabled: true
        },
        {
          type: 'INPUT',
          label: '采购单号',
          fieldName: 'XSDDHM',
          initialValue: '',
          
          disabled: true
        },
        {
          type: 'SELECT',
          label: '订单类型',
          initialValue: '',

          fieldName: 'XSDDLX',
          itemList: this.createDictList('3003'),
          
          disabled: true
        },
        // {
        //   title: '订单金额',
        //   sorter: true,
        //   dataIndex: 'XSYSJE',
        //   precision: 2,
        //   filter: true,
        //   filterType: 'number'
        // },
         {
          type: 'INPUT',
          label: '订单金额',
          fieldName: 'XSYSJE',
          initialValue: '',
          
          disabled: true
        },
        // {
        //   title: '可用余额',
        //   sorter: true,
        //   dataIndex: 'AVAIL_AMOUNT',
        //   precision: 2,
        //   filter: true,
        //   filterType: 'number'
        // },
        {
          type: 'DATE',
          fieldName: 'DDTBSJ',
          initialValue: '',

          label: '订单提报日期',
          dateFormat: 'yyyy-MM-dd',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系人',
          initialValue: '',

          fieldName: 'CONTACT_MAN',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系电话',
          initialValue: '',

          fieldName: 'CONTACT_PHONE',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '收货详细地址',
          initialValue: '',

          fieldName: 'XXSHDZ',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          initialValue: '',
          selfCols: 2,
          maxlength: 1000,
          fieldName: 'XSDDBZ',
          placeholder: '请输入...',
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '审核说明',
          initialValue: '',
          selfCols: 2,
          maxlength: 1000,
          fieldName: 'DDBHBZ',
          placeholder: '请输入...',
          disabled: true
        }
        
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          // sorter: true,
          width: 70,
          dataIndex: 'xuhao',
          sorter: true,
          render: props => {
            return <span>{props.row.$index + 1}</span>;
          },
          sorter: true
        },
        {
          title: '配件代码',
          width: 180,
          sorter: true,
          dataIndex: 'BJXMBH',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          width: 180,
          sorter: true,
          dataIndex: 'BJZWMC',
          showOverflowTooltip: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '销售包数量',
          sorter: true,
          dataIndex: 'SALES_PACK_NUM',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '服务站进价',
          sorter: true,
          dataIndex: 'IN_SERVICE_AMOUNT',
          precision: 2,
          filter: true,
          filterType: 'number'
        },
        {
          title: '采购数量',
          sorter: true,
          dataIndex: 'BSTXSL',
          precision: 2,
          filter: true,
          filterType: 'number',
          min: 0,
          max: Infinity,
          widht: 130
        },
        {
          title: '采购金额(元)',
          sorter: true,
          dataIndex: 'XSYSJE',
          precision: 2,
          summation: true,
          filter: true,
          filterType: 'number'
        }
      ];
    },
    //  changeSelect() {
    //         this.form.tableData = [];
      
    //     },
    
    refuByPurchase() {
      this.aduitRem = null;
      this.visible = true
      

    },
    closeDialogTop(){
       this.$emit('cancel');
    },
    aduit(e) {
       
          // console.log('this.form ============ :'+ JSON.stringify(this.form));
          auditOrder({
              id: this.top.ID,
              type:e,
              aduitRem:this.aduitRem
          }).then(res => {
            if(res.success){
              this.$notify.success('审核成功!');
              // 请求执行成后，刷新主页面子表格
              this.$emit('cancel');
            }else{
              this.$notify.error(res.errMsg);
              
            }
              
              
          });
            
    },
    
    // async translate(dealerCode) {
    //   let name = '';
    //   let res = await byAllInfo({ dealerCode: dealerCode });
    //   if (res.resultCode == 200 && res.data && res.data.records && res.data.records.length > 0) {
    //     name = res.data.records[0].companyName;
    //   }
    //   this.topFilterList.find(x => x.fieldName == 'ownerName').initialValue = name;
    // },
    async getStorage() {
      const ckRes = await getStorageList();
      const ckDict = ckRes.data.map(x => ({ text: x['STORAGE_NAME'], value: x['STORAGE_CODE'] }));
      this.storageDic = ckDict;
      this.tableColumns.find(x => x.dataIndex == 'STORAGE_CODE').filterItems = this.tableColumns.find(x => x.dataIndex == 'STORAGE_CODE').dictItems = ckDict;
    },
    async findBuyItems() {

      console.log('this.form ============ :'+ JSON.stringify(this.top));

      console.log('this.form ++++++++ :'+ JSON.stringify( this.topFilterList));
      this.topFilterList.map(x => {
        x.initialValue = this.top[x.fieldName];
      });
      let res = await partbuyStockInItemOEM({ partOrderId: this.top.ID });
      console.log('this.form ============ :'+ JSON.stringify(res));
      this.dataSource = res.data;
    }
  }
};
</script>
